package com.runoob.java8;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class Test01 {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("A", "B");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {

            }
        });


        Car car = Car.create(Car::new);
        car.setPrice("1223");
        System.out.println("car = " + car);

        List<Car> cars = Arrays.asList(car);
        cars.forEach(Car::collide);

    }
}

class Car {

    private String price;

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "price='" + price + '\'' +
                '}';
    }

    //Supplier是jdk1.8的接口，这里和lamda一起使用了
    public static Car create(final Supplier<Car> supplier) {
        return supplier.get();
    }

    public static void collide(final Car car) {

        System.out.println("Collided " + car.toString());
    }

    public void follow(final Car another) {
        System.out.println("Following the " + another.toString());
    }

    public void repair() {
        System.out.println("Repaired " + this.toString());
    }
}
